<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta name="description" content="hexo 博客搭建"><meta name="keywords" content="hexo"><meta name="author" content="kyren"><meta name="copyright" content="kyren"><title>hexo 博客搭建 | Kyren's Blog</title><link rel="shortcut icon" href="/melody-favicon.ico"><link rel="stylesheet" href="/css/index.css?version=1.9.0"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css?version=1.9.0"><meta name="format-detection" content="telephone=no"><meta http-equiv="x-dns-prefetch-control" content="on"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="dns-prefetch" href="https://hm.baidu.com"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cf87fcdbd9ab7cf93d894f7c219ae78f";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();</script><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><script src="https://v1.hitokoto.cn/?encode=js&amp;charset=utf-8&amp;select=.footer_custom_text" defer></script><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容:${query}"}},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  hexoVersion: '6.2.0'
} </script><meta name="generator" content="Hexo 6.2.0"></head><body><i class="fa fa-arrow-right" id="toggle-sidebar" aria-hidden="true"></i><div id="sidebar" data-display="true"><div class="toggle-sidebar-info text-center"><span data-toggle="切换文章详情">切换站点概览</span><hr></div><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar"></div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E3%80%81hexo%E4%B8%8E%E7%9B%B8%E5%85%B3%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85"><span class="toc-number">1.</span> <span class="toc-text">一、hexo与相关环境安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8C%E3%80%81hexo%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="toc-number">2.</span> <span class="toc-text">二、hexo初始化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E5%88%9B%E5%BB%BA%E6%96%B0%E5%8D%9A%E5%AE%A2"><span class="toc-number">3.</span> <span class="toc-text">三、创建新博客</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E7%94%9F%E6%88%90%E7%BD%91%E7%AB%99-amp-%E6%9C%AC%E5%9C%B0%E8%B0%83%E8%AF%95"><span class="toc-number">4.</span> <span class="toc-text">四、生成网站&amp;本地调试</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E8%A7%81%E9%94%99%E8%AF%AF"><span class="toc-number"></span> <span class="toc-text">常见错误</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99"><span class="toc-number"></span> <span class="toc-text">参考资料</span></a></div></div><div class="author-info hide"><div class="author-info__avatar text-center"><img src="https://avatars.githubusercontent.com/u/5827823?v=4"></div><div class="author-info__name text-center">kyren</div><div class="author-info__description text-center">huluo的技术博客</div><div class="follow-button"><a target="_blank" rel="noopener" href="https://github.com/huluo666">Follow Me</a></div><hr><div class="author-info-articles"><a class="author-info-articles__archives article-meta" href="/archives"><span class="pull-left">文章</span><span class="pull-right">239</span></a><a class="author-info-articles__tags article-meta" href="/tags"><span class="pull-left">标签</span><span class="pull-right">41</span></a><a class="author-info-articles__categories article-meta" href="/categories"><span class="pull-left">分类</span><span class="pull-right">29</span></a></div><hr><div class="author-info-links"><div class="author-info-links__title text-center">Links</div><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://192.168.2.212:9090/">Jira</a><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://192.168.2.212:8090/">Confluence</a><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://bloc.leniugame.com/">Leniu</a></div></div></div><div id="content-outer"><div class="no-bg" id="top-container"><div id="page-header"><span class="pull-left"> <a id="site-name" href="/">Kyren's Blog</a></span><i class="fa fa-bars toggle-menu pull-right" aria-hidden="true"></i><span class="pull-right menus">   <a class="site-page" href="/">主页</a><a class="site-page" href="/essay">随笔</a><a class="site-page" href="/archives">归档</a><a class="site-page" href="/tags">标签</a><a class="site-page" href="/categories">分类</a><a class="site-page" href="/about">关于</a></span><span class="pull-right"><a class="site-page social-icon search"><i class="fa fa-search"></i><span> 搜索</span></a></span></div><div id="post-info"><div id="post-title">hexo 博客搭建</div><div id="post-meta"><time class="post-meta__date"><i class="fa fa-calendar" aria-hidden="true"></i> 2016-02-01</time><span class="post-meta__separator">|</span><i class="fa fa-inbox post-meta__icon" aria-hidden="true"></i><a class="post-meta__categories" href="/categories/hexo/">hexo</a></div></div></div><div class="layout" id="content-inner"><article id="post"><div class="article-container" id="post-content"><h3 id="一、hexo与相关环境安装"><a href="#一、hexo与相关环境安装" class="headerlink" title="一、hexo与相关环境安装"></a>一、hexo与相关环境安装</h3><p><strong>1）、安装<code>node.js</code>，<code>git</code>环境</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">brew install node  #使用homebrew安装，这个Mac使用者必备吧</span><br><span class="line">brew install git   #如果安装了xcode，那么也就已经安装了git</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">brew uninstall node 卸载node</span></span><br></pre></td></tr></table></figure>

<p>查看node安装是否成功</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">node -v #输出版本信息 v6.x.x</span><br></pre></td></tr></table></figure>

<p><strong>2）、安装hexo</strong></p>
<p>hexo的安装使用最好查看[hexo官网][1]，官网很详细，因为版本升级，网上那些信息可能不准确而多走弯路</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$</span><span class="language-bash">sudo npm install hexo-cli -g <span class="comment">#全局安装Hexo客户端 3.0后</span></span></span><br></pre></td></tr></table></figure>

<p>升级</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">hexo v                      <span class="comment">#查看版本信息，检查是否安装成功</span></span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">npm update hexo-cli -g      <span class="comment">#更新hexo到最新版</span></span> </span><br></pre></td></tr></table></figure>

<h3 id="二、hexo初始化"><a href="#二、hexo初始化" class="headerlink" title="二、hexo初始化"></a>二、hexo初始化</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="built_in">cd</span> xxx.github.io      <span class="comment">#博客目录</span></span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">hexo init  folder     <span class="comment">#folder可不填</span></span></span><br></pre></td></tr></table></figure>

<p>如果指定 <code>folder</code>，便会在目前的资料夹建立一个名为 <code>folder</code> 的新资料夹；否则会在目前资料夹初始化。</p>
<p><strong>相关依赖库安装</strong></p>
<p>本人发现安装 <code>hexo-cli</code>时已安装以下库，如果出现相应错误，则需要安装。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">npm install  #这个命令会把需要的依赖环境都自动装上</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">hexo从 3.0 开始把服务器独立成了个别模块，所以要本地调试的话，还需要安装 hexo-server 才能使用</span></span><br><span class="line">npm install hexo-deployer-git --save  #如果没hexo d 失败则安装</span><br><span class="line">npm install hexo-server --save        #如果没hexo s 失败则安装</span><br></pre></td></tr></table></figure>



<h3 id="三、创建新博客"><a href="#三、创建新博客" class="headerlink" title="三、创建新博客"></a><strong>三、创建新博客</strong></h3><p>在当前目录<code>xxx.github.io</code></p>
<p><code>hexo new &quot;Hello World&quot;</code></p>
<h3 id="四、生成网站-amp-本地调试"><a href="#四、生成网站-amp-本地调试" class="headerlink" title="四、生成网站&amp;本地调试"></a>四、生成网站&amp;本地调试</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">hexo clean    #清除缓存文件 (db.json) 和已生成的静态文件 (public)。</span><br><span class="line">hexo generate #生成网站静态文件  可缩写为 hexo g</span><br><span class="line">hexo server   #启动服务，     可缩写为 hexo s </span><br><span class="line">hexo deploy   #部署网站 部署前，需要预先生成静态文件 可缩写为 hexo d</span><br></pre></td></tr></table></figure>

<p>常用组合命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">hexo d -g <span class="comment">#生成部署</span></span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">hexo s -g <span class="comment">#生成预览</span></span></span><br></pre></td></tr></table></figure>

<p>本地查看调试地址：<a target="_blank" rel="noopener" href="http://localhost:4000/">http://localhost:4000/</a></p>
<p>也可以指定端口如<code>hexo s -p 80</code></p>
<p>出现<code>Branch master set up to track remote branch master from https://github.com/xxxx.github.io.git.</code>表示部署成功</p>
<p>访问博客: [<a href="http://username.github.io][2]">http://username.github.io][2]</a></p>
<ul>
<li><p>Q：卸载Hexo？<br>A：3.0.0版本执行<code>$ npm uninstall hexo-cli -g</code>，之前版本执行<code>$ npm uninstall hexo -g</code>。</p>
<p>​</p>
</li>
</ul>
<h2 id="常见错误"><a href="#常见错误" class="headerlink" title="常见错误"></a>常见错误</h2><p><strong>（1）、Cannot find module</strong></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123; [Error: Cannot find module &#x27;./build/Release/DTraceProviderBindings&#x27;] code: &#x27;MODULE_NOT_FOUND&#x27; &#125;</span><br><span class="line">&#123; [Error: Cannot find module &#x27;./build/default/DTraceProviderBindings&#x27;] code: &#x27;MODULE_NOT_FOUND&#x27; &#125;   </span><br><span class="line">&#123; [Error: Cannot find module &#x27;./build/Debug/  DTraceProviderBindings&#x27;] code: &#x27;MODULE_NOT_FOUND&#x27; &#125;   </span><br></pre></td></tr></table></figure>
<p>这个问题烦了好久，最终找到解决办法。<br>$ npm install hexo –no-optional</p>
<p><strong>（2）、部署不成功</strong></p>
<p><code>nothing to commit, working directory clean</code><br>解决：3步</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1.rm -rf .deploy</span><br><span class="line">2.hexo generater</span><br><span class="line">3.hexo deploy</span><br></pre></td></tr></table></figure>


<p>建议用safari浏览器打开查看</p>
<p><strong>（3）、修改config.xml文件</strong></p>
<p><code>YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key at line 11, column 9:</code></p>
<p>检查一下是不是 冒号后面没有写空格？</p>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><p><a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/">https://hexo.io/zh-cn/</a><br>MAC 上 github + hexo 搭建博客教程</p>
<p><a target="_blank" rel="noopener" href="http://www.jianshu.com/p/fd878edb95e7">http://www.jianshu.com/p/fd878edb95e7</a></p>
<p>Homebrew简介及安装<br><a target="_blank" rel="noopener" href="http://www.cnblogs.com/lzrabbit/p/4032515.html">http://www.cnblogs.com/lzrabbit/p/4032515.html</a><br>Homebrew官网 <a target="_blank" rel="noopener" href="http://brew.sh/index/_zh-cn.html">http://brew.sh/index\_zh-cn.html</a></p>
<p>Hexo安装和配置<br>MAC 上 github + hexo 搭建博客教程</p>
<p><a target="_blank" rel="noopener" href="http://www.lovebxm.com/2017/05/30/buildBlog/">http://www.lovebxm.com/2017/05/30/buildBlog/</a></p>
<p><a target="_blank" rel="noopener" href="http://www.jianshu.com/p/b7886271e21a">http://www.jianshu.com/p/b7886271e21a</a><br><a target="_blank" rel="noopener" href="http://segmentfault.com/q/1010000002565189">http://segmentfault.com/q/1010000002565189</a></p>
<p><a target="_blank" rel="noopener" href="http://xiaopingblog.cn/2016/04/08/untitled-1460084538799/">http://xiaopingblog.cn/2016/04/08/untitled-1460084538799/</a></p>
<p>[手把手教你使用Hexo + Github Pages搭建个人独立博客][3]</p>
<p><a target="_blank" rel="noopener" href="https://dreajay.github.io/2014/11/24/hexo+github%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E7%B3%BB%E7%BB%9F/">https://dreajay.github.io/2014/11/24/hexo+github%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E7%B3%BB%E7%BB%9F/</a></p>
<p>域名绑定</p>
<p>[GitHub Pages 绑定来自阿里云的域名][4]</p>
<p>[1]:	<a target="_blank" rel="noopener" href="https://hexo.io/zh-cn/">https://hexo.io/zh-cn/</a><br>[2]:	<a target="_blank" rel="noopener" href="http://username.github.io/">http://username.github.io/</a><br>[3]:	<a target="_blank" rel="noopener" href="https://linghucong.js.org/2016/04/15/2016-04-15-hexo-github-pages-blog/">https://linghucong.js.org/2016/04/15/2016-04-15-hexo-github-pages-blog/</a><br>[4]:	<a target="_blank" rel="noopener" href="http://quantumman.me/blog/setting-up-a-domain-with-gitHub-pages.html">http://quantumman.me/blog/setting-up-a-domain-with-gitHub-pages.html</a></p>
</div></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">kyren</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://huluo666.gitee.io/2016/02/01/hexo博客搭建/">http://huluo666.gitee.io/2016/02/01/hexo博客搭建/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://huluo666.gitee.io">Kyren's Blog</a>！</span></div></div><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/hexo/">hexo</a></div><nav id="pagination"><div class="prev-post pull-left"><a href="/2016/02/02/hexo%E4%B8%BB%E9%A2%98%E5%AE%89%E8%A3%85/"><i class="fa fa-chevron-left">  </i><span>hexo主题安装</span></a></div><div class="next-post pull-right"><a href="/2016/01/07/Awesome%E7%B3%BB%E5%88%97/"><span>Awesome系列</span><i class="fa fa-chevron-right"></i></a></div></nav></div></div><footer><div class="layout" id="footer"><div class="copyright">&copy;2022 By kyren</div><div class="framework-info"><span>驱动 - </span><a target="_blank" rel="noopener" href="http://hexo.io"><span>Hexo</span></a><span class="footer-separator">|</span><span>主题 - </span><a target="_blank" rel="noopener" href="https://github.com/Molunerfinn/hexo-theme-melody"><span>Melody</span></a></div><div class="footer_custom_text">hitokoto</div><div class="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_page_pv"><i class="fa fa-file"></i><span id="busuanzi_value_page_pv"></span><span></span></span></div></div></footer><i class="fa fa-arrow-up" id="go-up" aria-hidden="true"></i><script src="https://cdn.jsdelivr.net/npm/animejs@latest/lib/anime.min.js"></script><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@latest/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-ui-pack@latest/velocity.ui.min.js"></script><script src="/js/utils.js?version=1.9.0"></script><script src="/js/fancybox.js?version=1.9.0"></script><script src="/js/sidebar.js?version=1.9.0"></script><script src="/js/copy.js?version=1.9.0"></script><script src="/js/fireworks.js?version=1.9.0"></script><script src="/js/transition.js?version=1.9.0"></script><script src="/js/scroll.js?version=1.9.0"></script><script src="/js/head.js?version=1.9.0"></script><script src="/js/search/local-search.js"></script><script>if(/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)) {
  $('#nav').addClass('is-mobile')
  $('footer').addClass('is-mobile')
  $('#top-container').addClass('is-mobile')
}</script><div class="search-dialog" id="local-search"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章"></div></div></div><hr><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fa fa-times"></i></span></div><div class="search-mask"></div></body></html>